##Title: Figure1
##2 June 2023
##Name: Shenghao Zhang

```{r Preparation}
library(sf)
library(sp)
library(cowplot)
library(tidyverse)
library(dplyr)

DRC_pko <- read.csv("DRC_pko.csv")
DRC_aid <- read.csv("DRC_aid.csv")
DRC_osv <- read.csv("DRC_osv.csv")

```

```{r for graph presentation}
######For graph presentation#######
#I use the orginal data of prio to plot the background of different countries as they give more specified parameters
#geometry   list(*)
prio = st_read(dsn = "priogrid_cell.shp", 
               layer = "priogrid_cell", 
               stringsAsFactors = F) %>% 
  mutate(gid = as.character(gid))
prio_yearly <- read.csv("priogrid_v1_01.csv", sep = ";")

prio_2007 <- prio_yearly %>%
  filter(year == 2007) %>%
  mutate(gid = as.character(gid)) 

prio.2007 <-left_join(prio, prio_2007) 

prio.2007.1 <- prio.2007 %>% filter(gwno == "490")

plot(st_geometry(prio.2007.1))

rm(prio)

prio_2007$gid <- as.numeric(prio_2007$gid)
prio_2007.1 <- prio_2007
prio_2007.1$gwno <- NULL
prio_2007.1$year  <- NULL


prio_DRC <- prio.2007 %>% filter(gwno == 490)
plot(st_geometry(prio_DRC))
  
```

```{r sample 2002}
pko_DRC_2002 <- DRC_pko %>% 
  filter(year == 2002)

aid_DRC_2002 <- DRC_aid %>%
  filter(year == 2002)

osv_binary_DRC_2002 <- DRC_osv %>%
  filter(year == 2002)

DRC_2002 <- ggplot(data = prio_DRC) +
  geom_sf() +
  # Adding conflict areas with a specific color and legend entry
  geom_sf(
    data = filter(prio_DRC, gid %in% osv_binary_DRC_2002$gid), 
    aes(fill = "One-Sided Violence Areas"), 
    alpha = 0.5, show.legend = TRUE
  ) +
  # Adding peacekeeping operations with combined shape, color, and stroke
  geom_point(
    data = pko_DRC_2002, 
    aes(x = long, y = lat, color = "Peacekeeping Operations", shape = "Peacekeeping Operations"), 
    size = 2.5, stroke = 1, alpha = 0.5, fill = "blue") +
  # Adding aid projects with combined shape, color, and stroke
  geom_point(
    data = aid_DRC_2002, 
    aes(x = long, y = lat, color = "Aid Projects", shape = "Aid Projects"), 
    size = 2.5, stroke = 1
  ) +
  # Customizing colors for each category
  scale_color_manual(
    name = "",
    values = c(
      "Conflict Areas" = "red", 
      "Peacekeeping Operations" = "blue", 
      "Aid Projects" = "darkgreen"
    )
  ) +
  # Customizing shapes for Peacekeeping Operations and Aid Projects
  scale_shape_manual(
    name = "",
    values = c(
      "Peacekeeping Operations" = 23, 
      "Aid Projects" = 8
    )
  ) +
  scale_fill_manual(
    name = "",
    values = c(
      "One-Sided Violence Areas" = "red")
  ) + ggtitle("2002") 


```



```{r}
####DRC 2003#####
pko_DRC_2003 <- DRC_pko %>% 
  filter(year == 2003)

aid_DRC_2003 <- DRC_aid %>%
  filter(year == 2003)

osv_binary_DRC_2003 <- DRC_osv %>%
  filter(year == 2003)

DRC_2003 <- ggplot(data = prio_DRC) +
  geom_sf() +
  geom_sf(
    data = filter(prio_DRC, gid %in% osv_binary_DRC_2003$gid), 
    aes(fill = "One-Sided Violence Areas"), 
    alpha = 0.5, show.legend = TRUE) +
  geom_point(
    data = pko_DRC_2003, 
    aes(x = long, y = lat, color = "Peacekeeping Operations", shape = "Peacekeeping Operations"), 
    size = 2.5, stroke = 1, alpha = 0.5, fill = "blue") +
  geom_point(
    data = aid_DRC_2003, 
    aes(x = long, y = lat, color = "Aid Projects", shape = "Aid Projects"), 
    size = 2.5, stroke = 1 ) +
  scale_color_manual(
    name = "",
    values = c(
      "Conflict Areas" = "red", 
      "Peacekeeping Operations" = "blue", 
      "Aid Projects" = "darkgreen") ) +
  scale_shape_manual(
    name = "",
    values = c(
      "Peacekeeping Operations" = 23, 
      "Aid Projects" = 8)) +
  scale_fill_manual(
    name = "",
    values = c(
      "One-Sided Violence Areas" = "red")) + ggtitle("2003") 

####DRC 2004#####
pko_DRC_2004 <- DRC_pko %>% 
  filter(year == 2004)

aid_DRC_2004 <- DRC_aid %>%
  filter(year == 2004)

osv_binary_DRC_2004 <- DRC_osv %>%
  filter(year == 2004)

DRC_2004 <- ggplot(data = prio_DRC) +
  geom_sf() +
  geom_sf(
    data = filter(prio_DRC, gid %in% osv_binary_DRC_2004$gid), 
    aes(fill = "One-Sided Violence Areas"), 
    alpha = 0.5, show.legend = TRUE) +
  geom_point(
    data = pko_DRC_2004, 
    aes(x = long, y = lat, color = "Peacekeeping Operations", shape = "Peacekeeping Operations"), 
    size = 2.5, stroke = 1, alpha = 0.5, fill = "blue") +
  geom_point(
    data = aid_DRC_2004, 
    aes(x = long, y = lat, color = "Aid Projects", shape = "Aid Projects"), 
    size = 2.5, stroke = 1 ) +
  scale_color_manual(
    name = "",
    values = c(
      "Conflict Areas" = "red", 
      "Peacekeeping Operations" = "blue", 
      "Aid Projects" = "darkgreen") ) +
  scale_shape_manual(
    name = "",
    values = c(
      "Peacekeeping Operations" = 23, 
      "Aid Projects" = 8)) +
  scale_fill_manual(
    name = "",
    values = c(
      "One-Sided Violence Areas" = "red")) + ggtitle("2004") 

####DRC 2005#####
pko_DRC_2005 <- DRC_pko %>% 
  filter(year == 2005)

aid_DRC_2005 <- DRC_aid %>%
  filter(year == 2005)

osv_binary_DRC_2005 <- DRC_osv %>%
  filter(year == 2005)

DRC_2005 <- ggplot(data = prio_DRC) +
  geom_sf() +
  geom_sf(
    data = filter(prio_DRC, gid %in% osv_binary_DRC_2005$gid), 
    aes(fill = "One-Sided Violence Areas"), 
    alpha = 0.5, show.legend = TRUE) +
  geom_point(
    data = pko_DRC_2005, 
    aes(x = long, y = lat, color = "Peacekeeping Operations", shape = "Peacekeeping Operations"), 
    size = 2.5, stroke = 1, alpha = 0.5, fill = "blue") +
  geom_point(
    data = aid_DRC_2005, 
    aes(x = long, y = lat, color = "Aid Projects", shape = "Aid Projects"), 
    size = 2.5, stroke = 1 ) +
  scale_color_manual(
    name = "",
    values = c(
      "Conflict Areas" = "red", 
      "Peacekeeping Operations" = "blue", 
      "Aid Projects" = "darkgreen") ) +
  scale_shape_manual(
    name = "",
    values = c(
      "Peacekeeping Operations" = 23, 
      "Aid Projects" = 8)) +
  scale_fill_manual(
    name = "",
    values = c(
      "One-Sided Violence Areas" = "red")) + ggtitle("2005") 

####DRC 2006#####
pko_DRC_2006 <- DRC_pko %>% 
  filter(year == 2006)

aid_DRC_2006 <- DRC_aid %>%
  filter(year == 2006)

osv_binary_DRC_2006 <- DRC_osv %>%
  filter(year == 2006)

DRC_2006 <- ggplot(data = prio_DRC) +
  geom_sf() +
  geom_sf(
    data = filter(prio_DRC, gid %in% osv_binary_DRC_2006$gid), 
    aes(fill = "One-Sided Violence Areas"), 
    alpha = 0.5, show.legend = TRUE) +
  geom_point(
    data = pko_DRC_2006, 
    aes(x = long, y = lat, color = "Peacekeeping Operations", shape = "Peacekeeping Operations"), 
    size = 2.5, stroke = 1, alpha = 0.5, fill = "blue") +
  geom_point(
    data = aid_DRC_2006, 
    aes(x = long, y = lat, color = "Aid Projects", shape = "Aid Projects"), 
    size = 2.5, stroke = 1 ) +
  scale_color_manual(
    name = "",
    values = c(
      "Conflict Areas" = "red", 
      "Peacekeeping Operations" = "blue", 
      "Aid Projects" = "darkgreen") ) +
  scale_shape_manual(
    name = "",
    values = c(
      "Peacekeeping Operations" = 23, 
      "Aid Projects" = 8)) +
  scale_fill_manual(
    name = "",
    values = c(
      "One-Sided Violence Areas" = "red")) + ggtitle("2006") 

####DRC 2007#####
pko_DRC_2007 <- DRC_pko %>% 
  filter(year == 2007)

aid_DRC_2007 <- DRC_aid %>%
  filter(year == 2007)

osv_binary_DRC_2007 <- DRC_osv %>%
  filter(year == 2007)

DRC_2007 <- ggplot(data = prio_DRC) +
  geom_sf() +
  geom_sf(
    data = filter(prio_DRC, gid %in% osv_binary_DRC_2007$gid), 
    aes(fill = "One-Sided Violence Areas"), 
    alpha = 0.5, show.legend = TRUE) +
  geom_point(
    data = pko_DRC_2007, 
    aes(x = long, y = lat, color = "Peacekeeping Operations", shape = "Peacekeeping Operations"), 
    size = 2.5, stroke = 1, alpha = 0.5, fill = "blue") +
  geom_point(
    data = aid_DRC_2007, 
    aes(x = long, y = lat, color = "Aid Projects", shape = "Aid Projects"), 
    size = 2.5, stroke = 1 ) +
  scale_color_manual(
    name = "",
    values = c(
      "Conflict Areas" = "red", 
      "Peacekeeping Operations" = "blue", 
      "Aid Projects" = "darkgreen") ) +
  scale_shape_manual(
    name = "",
    values = c(
      "Peacekeeping Operations" = 23, 
      "Aid Projects" = 8)) +
  scale_fill_manual(
    name = "",
    values = c(
      "One-Sided Violence Areas" = "red")) + ggtitle("2007") 


   
```





```{r output}
library(gridExtra)
grid.arrange(DRC_2002, DRC_2003, ncol = 2)

grid.arrange(DRC_2004, DRC_2005, ncol = 2)

grid.arrange(DRC_2006, DRC_2007, ncol = 2)
```

